package com.ChenYaRou.www.dao.impl;

import com.ChenYaRou.www.dao.ShopDao;
import com.ChenYaRou.www.po.Shop;
import com.ChenYaRou.www.utils.GenerateSql;
import com.ChenYaRou.www.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName ShopDaoImpl
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/12 0:00
 * @Version 1.0
 **/
public class ShopDaoImpl implements ShopDao {

    /**
     * 新建店铺
     * @param shop 新店铺
     * @return 更新条数
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int insert(Shop shop) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().insert(shop));
    }

    /**
     * 更新shop
     * @param newShop 新赋值内容
     * @param oldShop 更新的店铺
     * @return 更新条数
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int update(Shop newShop,Shop oldShop) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().update(newShop,oldShop));
    }

    /**
     * 查找shop集合 模糊搜索
     * @param shop 条件shop
     * @return
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public List<Shop> selectMore(Shop shop) throws IllegalAccessException,
            SQLException, NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectMore(GenerateSql.getInstance().select(shop), Shop.class);
    }

    /**
     * 查找确切的单一shop
     * @return 找到的shop
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public Shop selectSingle(Shop shop) throws IllegalAccessException,
            SQLException, NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectSimple(GenerateSql.getInstance().select(shop),Shop.class);
    }


    /**
     * 查找所有shop集合
     * @param shop 条件shop
     * @return
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public List<Shop> selectAll(Shop shop) throws IllegalAccessException, SQLException,
            NoSuchFieldException, InstantiationException{
        return JdbcUtil.getInstance().selectMore(GenerateSql.getInstance().selectAll(shop), Shop.class);
    }
}
